//登录
import request from '../plugins/umi-request';

const queryLogin = async ({username,password}) => {

  // if (第三方的包.api(username, password)){
    let params = new URLSearchParams();
    params.append('username',username);
    params.append('password',password);

    return request.get(`/api/login`,{params:params})
  // } else{
  //   return Promise.reject('格式有误')
  // }
};

//注册
const queryReg = async ({username,password,icon}) => {

  // if (第三方的包.api(username, password)){

  let params = new URLSearchParams();
  params.append('username',username);
  params.append('password',password);
  /*if (icon && icon.files.length > 0) {
    params.append('icon',icon.files[0]);
  }
*/
  return request(`/api/reg`,{method:'post',data:params})
  // } else{
  //   return Promise.reject('格式有误')
  // }
};

//自动登录
const queryAutoLogin = async () => request.get(`/api/islogin`);

//获取用户数据
const queryUser = async () => request.get(`/api/user`);

export {queryLogin,queryReg,queryAutoLogin,queryUser}